
r = 65; %%block repeatation.
n = 8; %% number of muscle.
fs = 2000; %% sampling rate
fnyq = fs/2;
lowpass_frequency = 100/fnyq; %% decided by FFT. set the cutoff frequency.
highpass_frequency = 10/fnyq; %% set the cuttoff frequency.

for i =1:r
 %%import raw_data by FOR loop.
 filename = sprintf('sEMG_trials/%d_EMG.csv',i)
 raw_data = importdata(filename)
 data = raw_data.data(:,1:8);
 %% set the time vector.
 time = zeros(length(raw_data),1);
 L = length(data);
for j =1:L
    time(j,1) = j/2000;
end

%%4th order highpass filter.

[b,a] = butter (4,highpass_frequency, 'high')
 for k = 1:n
   data(:,k) = filtfilt(b,a,data(:,k));
 end
 %% full wave rectification
 rec_signal = zeros(length(data),n);
 
 for m =1:n
   rec_signal(:,m) = abs(data(:,m));
 end 
 %% 4th lowpass filter.
[b,a] = butter(4,lowpass_frequency, 'low')
for k = 1:n
   data(:,k) = filtfilt(b,a,rec_signal(:,k));
end
 save_filename = sprintf('rec_signal/%d_rec_signal',i);
 xlswrite(save_filename,rec_signal);
end



    